package com.atnjupt.crud.bean;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用的返回信息
 * @author Wizarder
 * @create 2021-08-31 16:42
 */
public class Msg {
    //返回状态码 100成功，200失败
    private  int code;
    //
    //返回状态信息
    private String ms;

    //存储返回用户的信息
    private Map<String,Object> extend = new HashMap<>();

    /**
     * 处理成功方法
     * @return 成功对象
     */
    public static Msg success(){
        Msg msg = new Msg();
        msg.setCode(100);
        msg.setMs("处理成功！");
        return  msg;
    }

    /**
     * 处理失败
     * @return 失败对象
     */
    public static Msg fail(){
        Msg msg = new Msg();
        msg.setCode(200);
        msg.setMs("处理失败！");
        return msg;
    }

    public Msg add(String key,Object value){
        this.extend.put(key,value);
        return this;
    }

    public Msg() {
    }

    public Msg(int code, String ms, Map<String, Object> extend) {
        this.code = code;
        this.ms = ms;
        this.extend = extend;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMs() {
        return ms;
    }

    public void setMs(String ms) {
        this.ms = ms;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }
}
